package top.jlzhou.boot.config;

import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import top.jlzhou.config.CorsFilter;




@Configuration
public class ServletConfig {

	@Autowired
	private LoginFilter filter;
	

	/**
	 * 注册过滤器
	 * @return
	 */
	@Bean
    public FilterRegistrationBean<LoginFilter>  loginFilterRegistrationBean() {
        FilterRegistrationBean<LoginFilter> registrationBean = new FilterRegistrationBean<LoginFilter>();
        registrationBean.setFilter(filter);
        java.util.List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/member/*");
        registrationBean.setUrlPatterns(urlPatterns);
        registrationBean.setOrder(2);
        return registrationBean;
    }
	
	/**
	 * 跨域过滤器
	 * 优先执行
	 * @return
	 */
	@Bean
    public FilterRegistrationBean<CorsFilter>  corsFilterRegistrationBean() {
        FilterRegistrationBean<CorsFilter> registrationBean = new FilterRegistrationBean<CorsFilter>();
        registrationBean.setFilter(new CorsFilter());
        java.util.List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/*");
        registrationBean.setUrlPatterns(urlPatterns);
        registrationBean.setOrder(1);
        return registrationBean;
    }
	
}
